package org.xhnews.preferences;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

public class PreferencesEntry {

    public static byte[] serialize() throws IOException
    {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        DataOutputStream dos = new DataOutputStream(baos);
        dos.writeBoolean(Preferences.registered);
        dos.writeUTF(Preferences.registration_sn);
        dos.writeInt(Preferences.running_count);
        dos.writeUTF(Preferences.news_update_begin_time);
        dos.writeUTF(Preferences.news_update_end_time);
        dos.writeInt(Preferences.news_update_interval);
        dos.writeInt(Preferences.news_max_count_per_channel);
        dos.writeInt(Preferences.news_download_type);
        dos.writeUTF(Preferences.news_last_update_time);
        dos.writeBoolean(Preferences.news_is_readdown);
        dos.writeInt(Preferences.contact_update_interval);
        dos.writeInt(Preferences.message_update_interval);
        dos.writeInt(Preferences.location_city_id);
        dos.writeInt(Preferences.location_city_code);
        dos.writeUTF(Preferences.location_city_name);
        dos.writeInt(Preferences.location_province_id);
        dos.writeInt(Preferences.weather_update_interval);
        dos.writeUTF(Preferences.server_address);
        return baos.toByteArray();
    }
    public static void deserialize(byte[] data) throws IOException
    {
        ByteArrayInputStream bais = new ByteArrayInputStream(data);
        DataInputStream dis = new DataInputStream(bais);
        Preferences.registered=dis.readBoolean();
        Preferences.registration_sn=dis.readUTF();
        Preferences.running_count=dis.readInt();
        Preferences.news_update_begin_time=dis.readUTF();
        Preferences.news_update_end_time=dis.readUTF();
        Preferences.news_update_interval=dis.readInt();
        Preferences.news_max_count_per_channel=dis.readInt();
        Preferences.news_download_type=dis.readInt();
        Preferences.news_last_update_time=dis.readUTF();
        Preferences.news_is_readdown=dis.readBoolean();
        Preferences.contact_update_interval=dis.readInt();
        Preferences.message_update_interval=dis.readInt();
        Preferences.location_city_id=dis.readInt();
        Preferences.location_city_code=dis.readInt();
        Preferences.location_city_name=dis.readUTF();
        Preferences.location_province_id=dis.readInt();
        Preferences.weather_update_interval=dis.readInt();  
        Preferences.server_address=dis.readUTF();
    }
}
